package com.sajus.web.billing.admin.action;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.naming.NamingException;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.sajus.billing.client.delegate.BusinessDelegateFactory;
import com.sajus.billing.client.dto.AccountDTO;
import com.sajus.billing.client.dto.BillDTO;
import com.sajus.billing.client.dto.OfferingDTO;
import com.sajus.billing.client.dto.PromotionDTO;
import com.sajus.billing.client.dto.ServiceTypeDTO;

/**
 * Acts as a Struts 2 controller that responds
 * to a user action by setting the value
 * of the Message model class, and returns a String 
 * result.
 * @author Bruce Phillips
 *
 */
public class BillingScriptAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	
	/**
	 * The model class that stores the message
	 * to display in the view.
	 */

	private BillDTO bill;
	
	
	private AccountDTO account;
	
	/*
	 * Creates the MessageStore model object and 
	 * returns success.  The MessageStore model
	 * object will be available to the view.
	 * (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() throws Exception {
		String paramValue = ServletActionContext.getRequest().getParameter("accountId");
		if ( paramValue != null ){
			account = BusinessDelegateFactory.getInstance()
					.getAccountManager().getAccount( Integer.parseInt( paramValue ) );
		}
		
		
		
		return SUCCESS;
	}
	
	public String getStartDate(){
		Calendar c=Calendar.getInstance();
		c.set( c.get( c.YEAR ),c.get( c.MONTH ),1);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format( c.getTime() );
	}

	public String getEndDate(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format( Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH) );
	}

	public BillDTO getBill() {
		return bill;
	}

	public void setBill(BillDTO bill) {
		this.bill = bill;
	}

	public AccountDTO getAccount() {
		return account;
	}

	public void setAccount(AccountDTO account) {
		this.account = account;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
}
